<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'basic',
    'name' => '小冯的快乐',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm' => '@vendor/npm-asset',
        '@base_upload' => $params['base_upload_url'],
        '@upload' => $params['upload_url'],
        '@admin' => $params['cdn_url'] . '/admin/',
        '@index' => $params['cdn_url'] . '/index/',
        '@front' => $params['cdn_url'] . '/frontend/',
        '@download' => $params['cdn_url'] . '/download/',
        '@aui' => $params['cdn_url'] . '/aui/',
        '@jquery-ui' => $params['cdn_url'] . '/jquery-ui-1.12.1/'
    ],
    'components' => [
        'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    'sourceLanguage' => 'en-US',
                    'fileMap' => [
                        'app' => 'app.php',
                        'app/error' => 'error.php',
                    ],
                ],
                'yii*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@yii/messages',
                    'sourceLanguage' => 'en-US',
                ],
            ],
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'titarzhe123456',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser'
            ]
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => [
                        'xiaofengadminapi/user',
                        'xiaofengadminapi/classify',
                        'xiaofengadminapi/attr-name',
                        'xiaofengadminapi/attr-value',
                        'xiaofengadminapi/product',
                    ],
                    'extraPatterns' => [
                        'GET configs' => 'configs',
                        'GET info' => 'info',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => [
                        'xiaofengindexapi/classify',
                        'xiaofengindexapi/product',
                        'xiaofengindexapi/shopcart'
                    ],
                    'extraPatterns' => [
                    ]
                ],
            ],
        ],
        'wechat' => [
            'class' => 'jianyan\easywechat\Wechat',
            'userOptions' => [],  // 用户身份类参数
            'sessionParam' => 'wechatUser', // 微信用户信息将存储在会话在这个密钥
            'returnUrlParam' => '_wechatReturnUrl', // returnUrl 存储在会话中
            'rebinds' => [ // 自定义服务模块
                // 'cache' => 'common\components\Cache',
            ]
        ],
    ],
    'modules' => [
        'xiaofengindexapi' => [
            'class' => 'app\modules\indexapi\Module',
        ],
        'xiaofengadmin' => [
            'class' => 'app\modules\admin\Module',
        ],
        'xiaofengadminapi' => [
            'class' => 'app\modules\adminapi\Module',
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
        'generators' => [ //here
            'crud' => [
                'class' => 'yii\gii\generators\crud\Generator',
                'templates' => [
                    'adminlte' => '@vendor/dmstr/yii2-adminlte-asset/gii/templates/crud/simple',
                    'adminsimple' => '@app/gii/templates/crud/simple'
                ]
            ]
        ],
    ];
    //多语言
    $config['language'] = 'zh-CN';
    $config['timeZone'] = "Asia/Shanghai";
}

return $config;
